// 扩展1-2 类成员函数默认值(缺省参数值)
/**
 * 链接: https://blog.csdn.net/sailor_8318/article/details/3348383
 * 总结：
 * 1. 类成员函数，声明或定义中设置默认值，不可同时设置。
 * 2. 从右向左设置默认值
 * 3. 友元函数声明时设置默认值无效，除非该友元函数在类中定义，不过这样设置的友元函数无意义
 * 4. 静态成员函数设置默认值跟类普通成员函数一样
 * 
*/
#include <iostream>
class Test
{
public:
  void fun1(int, int, int);
  void fun2(int, int = 0, int = 0);
  void fun3(int a = 0, int b = 0, int c = 0)
  {
    std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
  }

  static void s_fun1(int, int, int);
  static void s_fun2(int, int = 0, int = 0);
  static void s_fun3(int a = 0, int b = 0, int c = 0)
  {
    std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
  }

  void friend f_fun1(int a, int b, int c = 1)
  {
    std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
  }
  friend void f_fun2(int, int, int);
  friend void f_fun3(int = 0, int = 0, int = 0);
  friend void f_fun4(int, int, int);
};
void f_fun2(int a, int b = 0, int c = 0)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}
void Test::fun1(int a, int b, int c = 0)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}
void Test::fun2(int a, int b, int c)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}

void Test::s_fun1(int a, int b, int c = 0)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}
void Test::s_fun2(int a, int b, int c)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}
void f_fun4(int a = 0, int b = 0, int c = 0)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}
int main()
{
  Test t1;
  t1.fun1(1, 2);
  t1.fun2(1);
  t1.fun3();

  Test::s_fun1(1, 2);
  Test::s_fun2(1);
  Test::s_fun3();

  // f_fun1(1,2); // 类内定义的友元，找不到
  f_fun2(1); // 类内定义并声明的友元，可以使用默认值
  // f_fun3(); // 类内声明并设置默认值的友元，无效
  f_fun4();

  printf("--------------end--------------\n");
  return 0;
}

void f_fun3(int a, int b, int c)
{
  std::cout << "a: " << a << " b : " << b << " c : " << c << std::endl;
}